<?php
/**
 * UserActivity model
 * 
 * @author    Evgeny Utehin <utehin@ebola.com.ua>
 * @copyright Copyright &copy; 2014 Ebola Communications 
 * @link      http://www.ebola.com.ua/ 
 */
class UserActivity extends CActiveRecord
{
    public static function model($className = __CLASS__)
    {
        return parent::model($className);
    }

    public function tableName()
    {
        return 'user_activity';
    }

    public function attributeLabels()
    {
        return array(
            'id'            => Yii::t('main', 'ID'),
            'entity'        => Yii::t('main', 'Entity'),
            'entity_id'     => Yii::t('main', 'Entity ID'),
            'user_id'       => Yii::t('main', 'User ID'),
            'action'        => Yii::t('main', 'Action'),
            'previous_data' => Yii::t('main', 'Previous data'),
            'current_data'  => Yii::t('main', 'Current data'),
            'description'   => Yii::t('main', 'Description'),
            'create_time'   => Yii::t('main', 'Create Time'),
        );
    }

    public function behaviors()
    {
        return array(
            'CTimestampBehavior' => array(
                'class' => 'zii.behaviors.CTimestampBehavior',
            ),
        );
    }

    public function search()
    {
        $criteria = new CDbCriteria;

        $criteria->compare('entity', $this->entity, true);
        $criteria->compare('entity_id', $this->entity_id);
        $criteria->compare('user_id', $this->user_id);
        $criteria->compare('action', $this->action);
        $criteria->compare('description', $this->description, true);
        $criteria->compare('create_time', $this->create_time, true);

        $pagination = array('pageSize' => 20);
        $sort       = array('defaultOrder' => 't.create_time DESC');

        return new CActiveDataProvider(get_class($this), compact('criteria', 'sort', 'pagination'));
    }
}
